-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support listOf, setOf with varargs #60
Conversation
# Conflicts: # lib/src/collection/set.dart # lib/src/collection/set_mutable.dart # lib/src/collections.dart # test/collection/iterable_extensions_test.dart
Codecov Report
@@ Coverage Diff @@
## master #60 +/- ##
=========================================
Coverage ? 99.46%
=========================================
Files ? 40
Lines ? 1693
Branches ? 0
=========================================
Hits ? 1684
Misses ? 9
Partials ? 0
Continue to review full report at Codecov.
|
lib/src/collections.dart
Outdated
} else if (arg0 != null) { | ||
args = [arg0]; | ||
} else { | ||
return emptyList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KList
can't offer a const
constructor. See #62
This question gave me a sleepless night 😅. Thanks for asking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Glad to help. 👿
That's too bad. But in any case, since the list is immutable then always returning the same class instance even if not const
, should be fine right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't return KList<dynamic>
for KList<String>
KList _empty = EmptyList();
KList<T> emptyList<T>() => _empty;
// error: type 'EmptyList<dynamic>' is not a subtype of type 'KList<String>'
emptyList<String>()
Will be added in all classes in another PR
The current API to create collections is rather verbose compared to kotlin. Since dart doesn't support varargs, it wasn't possible to copy Kotlins method signature.
But it turned out to be a false impression of Darts capabilities. Although varargs aren't available the same API can be achieved using optional positional arguments!
To simplify things,
null
cannot be used as argument oflistOf
. Also, the number of arguments is limited to 10.For lists with more elements and
null
values use the newlistFrom(Iterable)
method.Now every
<type>Of(args*)
function now has also a<type>From(Iterable)
companion.Additionally, as @rrousselGit pointed out, this library now offers a second way to create collections via factory constructors. Here's a complete list of all creation APIs:
This is a breaking change
This change is 100% breaking all existing implementations. But since this project is rather new (still 0.X), and not heavily used by many projects that's fine. It makes the API so much better!